package br.com.fumec.maze;

import br.com.fumec.util.Movements;

public class Moves {
	boolean left = false;
	boolean right = false;
	boolean up = false;
	boolean down = false;
	
	public Moves(boolean left, boolean right, boolean up, boolean down){
		this.left = left;
		this.right = right;
		this.up = up;
		this.down = down;
	}
	
	public boolean isLeft() {
		return left;
	}
	public void setLeft(boolean left) {
		this.left = left;
	}
	public boolean isRight() {
		return right;
	}
	public void setRight(boolean right) {
		this.right = right;
	}
	public boolean isUp() {
		return up;
	}
	public void setUp(boolean up) {
		this.up = up;
	}
	public boolean isDown() {
		return down;
	}
	public void setDown(boolean down) {
		this.down = down;
	}
	
	public Movements[] getMovements(){
		int size = 0;
		if(this.isLeft()){
			size++;
		}
		
		if(this.isRight()){
			size++;
		}
		
		if(this.isUp()){
			size++;
		}
		
		if(this.isDown()){
			size++;
		}
		
		Movements[] movements = new Movements[size];
		int i = 0;
		if(this.isLeft()){
			movements[i] = Movements.LEFT;
			i++;
		}
		
		if(this.isRight()){
			movements[i] = Movements.RIGHT;
			i++;
		}
		
		if(this.isUp()){
			movements[i] = Movements.UP;
			i++;
		}
		
		if(this.isDown()){
			movements[i] = Movements.DOWN;
			i++;
		}		
		
		return movements;
	}
	
	public String toString(){
		String result = "";
		Movements[] movements = this.getMovements();
		for(int i = 0; i < movements.length; i++){
			if(movements[i] == Movements.LEFT){
				result= "LEFT "+result;
			}
			
			if(movements[i] == Movements.RIGHT){
				result= "RIGHT "+result;
			}
			
			if(movements[i] == Movements.UP){
				result= "UP "+result;
			}
			
			if(movements[i] == Movements.DOWN){
				result= "DOWN "+result;
			}
		}
		return result;
	}
}